package com.tensquare.article.service;

import com.tensquare.article.dao.CommentDao;
import com.tensquare.article.pojo.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import util.IdWorker;

import java.util.Date;
import java.util.List;

/**
 * @Auther: 高源
 * @Time:2020/5/4 13:24
 * @Description: 评论service
 * @version:1.0
 */

@Service
public class CommentService {

    @Autowired
    private CommentDao commentDao;

    @Autowired
    private IdWorker idWorker;

    /**
     * 新增
     * @param comment
     */
    public void add(Comment comment){
        comment.set_id(idWorker.nextId()+"");
        comment.setPublishdate(new Date());
        commentDao.save(comment);
    }

    /**
     * 根据文章id查询
     */
    public List<Comment> findByArticleid(String articleid){
        return commentDao.findByArticleid(articleid);
    }

    /**
     * 删除
     * @param articleid
     */
    public void deleteByid(String articleid ){
        commentDao.deleteById(articleid);
    }
}
